Update plugin documentation related to dispatching events Plugins should use EventDispatcher, not ChangeHooksRunner. Change-Id: I8c5cb25b04670ea552fb851b2f23891336bd73b4
diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt index 5a045e0..3f1ab93 100644 --- a/Documentation/dev-plugins.txt +++ b/Documentation/dev-plugins.txt
@@ -425,10 +425,35 @@ Gerrit's `stream-events` ssh command will receive them. To send an event, the plugin must invoke one of the `postEvent` -methods in the `ChangeHookRunner` class, passing an instance of +methods in the `EventDispatcher` interface, passing an instance of its own custom event class derived from `com.google.gerrit.server.events.Event`. +[source,java] +---- +import com.google.gerrit.common.EventDispatcher; +import com.google.gerrit.extensions.registration.DynamicItem; +import com.google.gwtorm.server.OrmException; +import com.google.inject.Inject; + +class MyPlugin { + private final DynamicItem<EventDispatcher> eventDispatcher; + + @Inject + myPlugin(DynamicItem<EventDispatcher> eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + + private void postEvent(MyPluginEvent event) { + try { + eventDispatcher.get().postEvent(event); + } catch (OrmException e) { + // error handling + } + } +} +---- + Plugins which define new Events should register them via the `com.google.gerrit.server.events.EventTypes.registerClass()` method. This will make the EventType known to the system.